import { Component, OnInit,Input } from '@angular/core';
var $=require('jquery');
var base=require('modules/base.js');
console.log(window);
@Component({
  selector: 'app-base-login',
  templateUrl: './base-login.component.html',
  styleUrls: ['./base-login.component.less']
})
export class BaseLoginComponent implements OnInit {
	//点击注册账号跳转到注册页面
	@Input() loginp;
	ismycountshow=!0;
	isLoginshow=!0;
	password='';
	username='';
  rightNow() {
      $(".logined").addClass("display-none");
      $(".register").css('display',"block")
      $(".login2").addClass("active");
      $(".login1").removeClass("active");
  };
  //关闭登录页面
  closelogin(e) {
      this.loginp.isLoginShow=!1;
  };
  //登录接口的触发事件
  denglu() {
      var that = this;
      if (this.password == "") {
          $('.y-errorMsg').text("请输入密码");
      }
      if (this.username == "") {
          $('.y-errorMsg').text("请输入用户名");
      }
      if (this.username == "" || this.password == "") {
          return;
      }
      base.request(base.api(40), { username: this.username, password: this.password }, function (d) {
          this.loginSuccess(d);
      }, function (d) {
          this.loginFail(d);
      }); //登录接口
  };
	loginSuccess(data) {
    //登录接口返回成功
    sessionStorage.setItem("sid", data.sid);
    sessionStorage.setItem("username", this.username);
    $(".y-errorMsg").text("登录成功");
    this.ismycountshow = !this.ismycountshow;
    this.isLoginshow = !this.isLoginshow;
    //延迟一秒让登录框消失
    var that = this;
    setTimeout(function () {
        $("#login").hide();
//      that.$router.go(0);
    }, 1000);
};
loginFail(data) {
    //登录接口返回失败
    if (data.code == -1) {
        $(".y-errorMsg").text("" + data.msg + "");
        $("#password").val("");
    }
};
	
  constructor() { 
  	window['login']=this;
  }

  ngOnInit() {
  }

}
